package com.koron.operation.classes.form.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.interceptor.OrderByInterceptor;
import com.koron.operation.classes.form.bean.po.ClassesFormRecord;
import com.koron.operation.classes.form.bean.query.ClassesFormRecordQuery;
import com.koron.operation.classes.form.bean.vo.ClassesFormRecordVO;
import com.koron.operation.classes.form.mapper.ClassesFormRecordMapper;
import com.koron.operation.classes.form.service.ClassesFormRecordService;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 月度排班打卡记录表(ClassesFormRecord)表服务实现类
 *
 * @author jzp
 * @since 2023-05-19 10:06:47
 */
@Service
public class ClassesFormRecordServiceImpl implements ClassesFormRecordService {

    /**
     * 通过ID查询单条数据
     */
    @Override
    @TaskAnnotation("getById")
    public ClassesFormRecord getById(SessionFactory factory, String id) {
        ClassesFormRecordMapper mapper = factory.getMapper(ClassesFormRecordMapper.class);
        return mapper.selectById(id);
    }

    /**
     * 查询所有数据
     */
    @Override
    @TaskAnnotation("list")
    public List<ClassesFormRecord> list(SessionFactory factory, ClassesFormRecord classesFormRecord) {
        ClassesFormRecordMapper mapper = factory.getMapper(ClassesFormRecordMapper.class);
        return mapper.selectList(classesFormRecord);
    }

    @Override
    @TaskAnnotation("listVo")
    public List<ClassesFormRecordVO> listVo(SessionFactory factory, ClassesFormRecordQuery query) {
        ClassesFormRecordMapper mapper = factory.getMapper(ClassesFormRecordMapper.class);
        return mapper.selectVoList(query);
    }

    @Override
    @TaskAnnotation("pageVo")
    public PageInfo<ClassesFormRecordVO> pageVo(SessionFactory factory, PageQuery pageQuery, ClassesFormRecordQuery query) {
        OrderByInterceptor.setOrderBy(pageQuery.getOrders());            // 设置排序，若不设置排序，插件会因为没有排序字段而直接跳过，不会影响分页插件
        PageHelper.startPage(pageQuery.getPage(), pageQuery.getPageSize());  //设置分页
        List<ClassesFormRecordVO> classesFormRecordList = listVo(factory, query);
        return new PageInfo<>(classesFormRecordList);
    }

    /**
     * 新增数据
     */
    @Override
    @TaskAnnotation("save")
    public boolean save(SessionFactory factory, ClassesFormRecord classesFormRecord) {
        ClassesFormRecordMapper mapper = factory.getMapper(ClassesFormRecordMapper.class);
        return mapper.insertOrUpdate(classesFormRecord) > 0;
    }

    /**
     * 修改数据
     */
    @Override
    @TaskAnnotation("update")
    public boolean update(SessionFactory factory, ClassesFormRecord classesFormRecord) {
        ClassesFormRecordMapper mapper = factory.getMapper(ClassesFormRecordMapper.class);
        return mapper.update(classesFormRecord) > 0;
    }

    /**
     * 通过主键删除数据
     */
    @Override
    @TaskAnnotation("deleteById")
    public boolean deleteById(SessionFactory factory, String id) {
        ClassesFormRecordMapper mapper = factory.getMapper(ClassesFormRecordMapper.class);
        return mapper.hidden(id) > 0;
    }
}
